package guyubao.com.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import guyubao.com.controller.BaseController;
import guyubao.com.controller.JDAccountController;
import guyubao.com.entity.RestBean;
import guyubao.com.entity.dto.JDAccountDto;
import guyubao.com.entity.dto.JDAccountInfoDto;
import guyubao.com.entity.dto.JDCertificateDto;
import guyubao.com.entity.vo.request.JDCertificateVoRequest;
import guyubao.com.entity.vo.response.JDAccountInfoVo;
import guyubao.com.entity.vo.response.JDAccountVo;
import guyubao.com.entity.vo.response.JDCertificateVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
@Validated
@RestController
@RequestMapping("/api/admin/JDAccount")
@Tag(name = "京东账号相关", description = "账号信息的增删改查")
public class AdminJDAccountController extends BaseController {
    @Resource
    JDAccountController jdAccountController;
    @Operation(summary ="获取用户下所有uid")
    @GetMapping("/uIds")
    public RestBean<List<String>> getUIds(@RequestParam String id,
                                          @RequestAttribute String role){
        if(!isAdmin(role))return RestBean.forbidden("您不是管理员");
        return jdAccountController.innerGetUIds(id);
    }
    @Operation(summary ="根据uid获取基础 账号 昵称 备注")
    @GetMapping("/account")
    public RestBean<JDAccountDto> getJDAccount(@RequestParam String uid,
                                               @RequestAttribute String role){
        if(!isAdmin(role))return RestBean.forbidden("您不是管理员");
        return jdAccountController.innerGetJDAccount(uid);
    }
    @Operation(summary ="获取用户下所有账户 uid pin 昵称 备注 次数 状态 ")
    @GetMapping("/accounts")
    public RestBean<List<JDAccountVo>> getJDAccounts(@RequestParam String id,
                                                     @RequestAttribute String role){
        if(!isAdmin(role))return RestBean.forbidden("您不是管理员");
        return jdAccountController.innerGetJDAccounts(id);
    }
    @Operation(summary ="获取用户下所有账户 uid pin 昵称 备注 次数 状态 ")
    @GetMapping("/accountsPage")
    public RestBean<Page<JDAccountVo>> getJDAccountsPage(@RequestParam String id,
                                                         @RequestParam long size,@RequestParam long current, @RequestAttribute String role){
        if(!isAdmin(role))return RestBean.forbidden("您不是管理员");
        return jdAccountController.innerGetJDAccountsPage(id,size,current);
    }
    @Operation(summary ="根据uid获取该账号所有信息")
    @GetMapping("/accountInfos")
    public RestBean<JDAccountInfoVo> getJDAccountInfos(@RequestParam String uid,
                                                       @RequestAttribute String role){
        if(!isAdmin(role))return RestBean.forbidden("您不是管理员");
        return jdAccountController.innerGetJDAccountInfos(uid);
    }

    @Operation(summary ="根据uid获取该账号简略信息")
    @GetMapping("/accountInfo")
    public RestBean<JDAccountInfoDto> getJDAccountInfo(@RequestParam String uid,
                                                       @RequestAttribute String role){
        if(!isAdmin(role))return RestBean.forbidden("您不是管理员");
        return jdAccountController.innerGetJDAccountInfo(uid);
    }

    @Operation(summary ="根据uid获取该账号凭证信息")
    @GetMapping("/proof")
    public RestBean<JDCertificateDto> getJDAccountProof(@RequestParam String uid,
                                                        @RequestAttribute String role){
        if(!isAdmin(role))return RestBean.forbidden("您不是管理员");
        return jdAccountController.innerGetJDAccountProof(uid);
    }
    @Operation(summary ="根据uid获取该账号凭证 次数 状态")
    @GetMapping("/proofBase")
    public RestBean<JDCertificateVo> getJDAccountProofBase(@RequestParam String uid,
                                                           @RequestAttribute String role){
        if(!isAdmin(role))return RestBean.forbidden("您不是管理员");
        return jdAccountController.innerGetJDAccountProofBase(uid);
    }
    @Operation(summary ="根据uid删除绑定")
    @DeleteMapping("/account")
    public RestBean<Void> delJDAccount(@RequestParam String uid,
                                       @RequestAttribute String role){
        if(!isAdmin(role))return RestBean.forbidden("您不是管理员");
        return jdAccountController.innerDelJDAccount(uid);
    }
    @Operation(summary ="根据uid更新备注")
    @PutMapping("/comment")
    public RestBean<Void> updateJDAccountComment(@RequestParam String uid,
                                                 @RequestParam String data,
                                                 @RequestAttribute String role){
        if(!isAdmin(role))return RestBean.forbidden("您不是管理员");
        return jdAccountController.innerUpdateJDAccountComment(uid,data);
    }
    @Operation(summary ="根据uid更新京东账号")
    @PutMapping("/account")
    public RestBean<Void> updateJDAccountAccount(@RequestParam String uid,
                                                 @RequestParam String data,
                                                 @RequestAttribute String role){
        if(!isAdmin(role))return RestBean.forbidden("您不是管理员");
        return jdAccountController.innerUpdateJDAccountAccount(uid,data);
    }
    @Operation(summary ="根据uid更新京东昵称")
    @PutMapping("/nickname")
    public RestBean<Void> updateJDAccountNickname(@RequestParam String uid,
                                                 @RequestParam String data,
                                                 @RequestAttribute String role){
        if(!isAdmin(role))return RestBean.forbidden("您不是管理员");
        return jdAccountController.innerUpdateJDAccountNickname(uid,data);
    }
    @Operation(summary ="更新账号凭证信息")
    @PutMapping("/proof")
    public RestBean<Void> updateJDCertificate(@Parameter(description = "json提供凭证和uid",
            example = "{'pt_key':'xxx','pt_token':'xxx','pt_pin':'xxx','uid':'xxx'}")
                                              @RequestBody JDCertificateVoRequest vo,
                                              @RequestAttribute String role){
        if(!isAdmin(role))return RestBean.forbidden("您不是管理员");
        return jdAccountController.innerUpdateJDCertificate(vo);
    }
}
